package com.ruoyi.web.controller.app;

import com.ruoyi.app.domain.AppCaseInfo;
import com.ruoyi.app.domain.AppCaseReceipt;
import com.ruoyi.app.service.IAppCaseInfoService;
import com.ruoyi.app.service.IAppCaseReceiptService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.AppBaseEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Api(value="回执信息",tags={"回执信息"})
@RequestMapping("app/receip")
@RestController
public class AppCaseReceiptController extends AppBaseController {

    @Autowired
    private IAppCaseReceiptService iAppCaseReceiptService;
    @Autowired
    private IAppCaseInfoService iAppCaseInfoService;

    @PostMapping("/save")
    @ApiOperation(value = "帖子信息保存接口",response= AppCaseReceipt.class, notes = "帖子信息保存接口")
    @ApiImplicitParam(name = "X-TaiChi-Token", value = "apyexnioxzsa11cqxy2ur2p9jkp46hz7",
            paramType = "header", dataType = "string", required = true)
    public AjaxResult save(@RequestBody @ApiParam(name="回执对象",value="传入json格式",required=true) AppCaseReceipt appCaseReceipt){

        AppCaseInfo appCaseInfo = iAppCaseInfoService.selectAppCaseInfoById(appCaseReceipt.getCaseId());
        if(null==appCaseInfo){
            return AjaxResult.error("数据异常");
        }
        if(appCaseInfo.getCaseCompanyCode()!=getUserDeptCode()){
            return AjaxResult.error("只能处理自己部门的数据");
        }
        appCaseReceipt.setReceiptTime(new Date());
        appCaseReceipt.setOperatorId(getUserId());
        appCaseReceipt.setOperator(getUserName());
        iAppCaseReceiptService.insertAppCaseReceipt(appCaseReceipt);
        return AjaxResult.success("保存成功！");

    }


}
